package spring.test4;

import com.blackhorse.service.AccountService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo4_SpringTransactionControl_Program {
    ApplicationContext applicationContext;

    /**
     * 编程式事务控制的转账测试
     * 配置文件：transactionControl\tx_program.xml
     * com.blackhorse.transactionControl.service.program.AccountServiceTXImplWithTransactionTemplate
     * dao：com.blackhorse.transactionControl.dao.AccountDaoTXImpl
     */
    @Test
    public void testAccountServiceWithTransactionTemplate() {
        String xmlPath = "transactionControl/tx_program.xml";
        applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        AccountService service = (AccountService) applicationContext.getBean("accountServiceTXImplWithTransactionTemplate");
        service.transfer("张三", "李四", 100);
        System.out.println("转账完成");
    }

}
